import utime as time
from modem import net as mynet
import modem
import http
import sntp
import yun_network

pyversion="20240000"

#py升级包里包含的是haas506的python脚本升级包，.zip格式的文件
def ota_py_app():
    global ota_flag
    ota_url = "your url"
   
    htp = http.client()
    ota_flag = 0
    if htp.fotaPy(ota_url) == 0:  #py固件下载成功，重启设备
        print('------------------htp.pyfotaPy')
        time.sleep_ms(1000)
        modem.reboot()
    else:
        print('pyota failed!')

#pac升级包里包含的是haas506的pac差分升级包，.pack格式的文件
def ota_pac_app():
    global ota_flag
    htp = http.client()
    ota_url = "your url"
    if htp.fotaSys(ota_url) == 0:  #pac固件下载成功，重启设备
        print('------------------htp.pacfotaPy')
        time.sleep_ms(1000)
        modem.reboot()
    else:
        print('pacota failed!')
   

if __name__ == '__main__':
    yun_network.connect_network()           #连接网络
    sntp.settime()#SNTP对时
    print("csq:",mynet.getCsq())
    pacversion = modem.info.getDevFwVersion()
    print('---------------------------pacversion={}'.format(pacversion))
    print('pyversion:{}'.format(pyversion))
    time.sleep(5)
    ota_py_app()
    # ota_pac_app()
    while True:
        print('httpota test')
        time.sleep(3)